package com.lvyq.javaprint.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import java.io.IOException;

/** 解决接收MultipartFile类型数据时临时路径删除异常的问题异常-即使删除此配置类也不会影响打印操作
 * 8月 08, 2024 12:27:29 下午 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor doRun
 * 严重: Error running socket processor
 * java.io.UncheckedIOException: Cannot delete C:\Users\admin\AppData\Local\Temp\.tmp
 *
 * @author lvyq
 * @version 1.0
 * Create by 2024-08-08 12:00
 */

@Configuration
public class MultipartConfig {

    @Bean
    public MultipartResolver multipartResolver() throws IOException {
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
        multipartResolver.setDefaultEncoding("utf-8");
        multipartResolver.setMaxUploadSize(50000000); // 设置最大上传文件大小
        multipartResolver.setMaxInMemorySize(50000000); // 设置最大内存大小
        multipartResolver.setUploadTempDir(new FileSystemResource("/temp/dir")); // 设置临时目录
        return multipartResolver;
    }
}
